package com.lineage.server.serverpackets;

import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import java.util.Iterator;

public class S_RetrieveElfList extends ServerBasePacket {
  private byte[] _byte = null;
  
  public S_RetrieveElfList(int objid, L1PcInstance pc) {
    if (pc.getInventory().getSize() < 180) {
      int size = pc.getDwarfForElfInventory().getSize();
      if (size > 0) {
        writeC(176);
        writeD(objid);
        writeH(size);
        writeC(9);
        Iterator localIterator = pc.getDwarfForElfInventory().getItems().iterator();
        while (localIterator.hasNext()) {
          Object itemObject = localIterator.next();
          L1ItemInstance item = (L1ItemInstance)itemObject;
          writeD(item.getId());
          int i = item.getItem().getUseType();
          if (i < 0)
            i = 0; 
          writeC(i);
          writeH(item.get_gfxid());
          writeC(item.getBless());
          writeD((int)Math.min(item.getCount(), 2000000000L));
          writeC(item.isIdentified() ? 1 : 0);
          writeS(item.getViewName());
        } 
        writeH(30);
        writeD(0);
      } 
    } else {
      pc.sendPackets(new S_ServerMessage(263));
    } 
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
